<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" th:href="@{../lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" href="../css/public.css" th:href="@{../css/public.css}" media="all">
    <link rel="stylesheet" href="../css/layuimini.css?v=2.0.1" th:href="@{../css/layuimini.css?v=2.0.1}" media="all">

</head>
<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="saveBtn">



        <div class="layui-form-item">
            <label class="layui-form-label required">访客姓名</label>
            <div class="layui-input-block">
                <input type="text" name="visName"  lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">联系方式</label>
            <div class="layui-input-block">
                <input type="text" name="visPhone"  lay-verify="required|phone" lay-reqtext="手机号不能为空" placeholder="请输入联系方式" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="resId">
            <label class="layui-form-label required">小区名称</label>
            <div class="layui-input-block">
                <input type="text" name="addName"    lay-reqtext="小区名称不能为空" placeholder="请输入小区名称" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="padding-left: 40px">
            <div class="layui-inline">
                <label class="layui-form-label required">访问楼号</label>
                <div class="layui-input-inline">
                    <input type="text" name="addHouse"  lay-verify="required" lay-reqtext="受访地址不能为空" placeholder="请输入访问的楼号" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required">访问单元号</label>
                <div class="layui-input-inline">
                    <input type="text" name="addUnit"  lay-verify="required" lay-reqtext="受访地址不能为空" placeholder="请输入访问的单元号" value="" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <input type="text" name="visRemark" placeholder="备注信息" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="recPersonId" >
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认添加</button>
            </div>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" th:src="@{../lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script src="../js/lay-config.js?v=2.0.0" th:src="@{../js/lay-config.js}" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();


        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var datas = data.field;
            var loadIndex = layer.load(2);
            $.ajax({
                url: '/visitors/addVisitor',
                type: 'post',
                data: datas,
                dataType: "json",
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code == '200') {
                        layer.msg(res.msg, {
                            icon: 6,
                            time: 1000},function () {
                            parent.window.location.reload();//刷新页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex)
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                }, error: function () {
                    layer.close(loadIndex);
                    layer.msg('网页出错了,即将跳转异常页', {icon: 2,time:1500});
                    window.location.href = '/User/404'
                }
            });
            return false;
        });

    });
</script>
</html>
